package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.entity.OrderTransportDetailed;
import cn.stylefeng.guns.modular.order.mapper.OrderTransportDetailedMapper;
import cn.stylefeng.guns.modular.order.model.params.OrderTransportDetailedParam;
import cn.stylefeng.guns.modular.order.model.result.OrderTransportDetailedResult;
import  cn.stylefeng.guns.modular.order.service.OrderTransportDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 货运订单明细表 服务实现类
 */
@Service
public class OrderTransportDetailedServiceImpl extends ServiceImpl<OrderTransportDetailedMapper, OrderTransportDetailed> implements OrderTransportDetailedService {

    @Override
    public void add(OrderTransportDetailedParam param){
        OrderTransportDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(OrderTransportDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(OrderTransportDetailedParam param){
        OrderTransportDetailed oldEntity = getOldEntity(param);
        OrderTransportDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public OrderTransportDetailedResult findBySpec(OrderTransportDetailedParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<OrderTransportDetailedResult> findListBySpec(OrderTransportDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(OrderTransportDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(OrderTransportDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private OrderTransportDetailed getOldEntity(OrderTransportDetailedParam param) {
        return this.getById(getKey(param));
    }

    private OrderTransportDetailed getEntity(OrderTransportDetailedParam param) {
        OrderTransportDetailed entity = new OrderTransportDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<OrderTransportDetailedResult> findTotaListBySpec(
			OrderTransportDetailedParam orderTransportDetailedParam) {
		return this.baseMapper.findTotaListBySpec(orderTransportDetailedParam);
	}

	@Override
	public List<OrderTransportDetailedResult> findListBySpecWeiPei(OrderTransportDetailedParam param) {
		return this.baseMapper.findListBySpecWeiPei(param);
	}

	@Override
	public boolean saveBatchList(List<OrderTransportDetailedParam> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public void deleteBySpec(OrderTransportDetailedParam detailedParam) {
		this.baseMapper.deleteBySpec(detailedParam);
	}

}
